package com.his.j259w264.controller;

import com.his.j259w264.pojo.RegistrationInformation;
import com.his.j259w264.service.impl.RegistrationInformationServiceImpl;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 挂号信息表(RegistrationInformation)表控制层
 *
 * @author EdgeYu
 * @version 1.0
 * @since 2021-09-15 20:27:16
 */

@RestController
@RequestMapping("/registrationInformation")
@Api(value = "挂号信息表(RegistrationInformation)管理", tags = "挂号信息表(RegistrationInformation)管理接口API")
@ApiResponses({
        @ApiResponse(code = 400, message = "请求参数不完整或者错误"),
        @ApiResponse(code = 404, message = "找不到页面"),
        @ApiResponse(code = 405, message = "请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code = 406, message = "页面地址和接口名冲突"),
        @ApiResponse(code = 415, message = "请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code = 500, message = "后台服务逻辑错误")
})
public class RegistrationInformationController {
    /**
     * 服务对象
     */
    @Resource
    private RegistrationInformationServiceImpl registrationInformationServiceImpl;


    /**
     * 分页查询当天所有挂号信息，可以根据患者姓名，患者身份证号查询，如果给定时间区间，则按照时间区间进行查询
     * TimePeriod:时间段
     *
     * @param index          需要查询的页码
     * @param limit          分页数量
     * @param patientName    病人姓名
     * @param departmentName 科室名称
     * @param idCard         病人身份证号
     * @param startTime      起始时间
     * @param endTime        结束时间
     * @return 返回挂号信息及病人信息
     */
    @RequestMapping(value = "/selectForPageByPatientNameAndIdCardAndTimePeriod", method = RequestMethod.GET)
    @ApiOperation(value = "分页查询当天所有挂号信息，可以根据患者姓名，患者身份证号查询，如果给定时间区间，则按照时间区间进行查询", notes = "分页查询当天所有挂号信息，可以根据患者姓名，患者身份证号查询，如果给定时间区间，则按照时间区间进行查询,TimePeriod:时间段", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "int", required = true, example = "1"),
            @ApiImplicitParam(name = "limit", value = "分页数量", paramType = "query", dataType = "int", required = true, example = "10"),
            @ApiImplicitParam(name = "patientName", value = "病人姓名", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "departmentName", value = "科室名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "idCard", value = "病人身份证号", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "起始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    public Map<String, Object> selectForPageByPatientNameAndIdCardAndTimePeriod(@RequestParam(name = "page") int index, @RequestParam(name = "limit") int limit,
                                                                                String patientName, String departmentName, String idCard, String startTime, String endTime) {
        return registrationInformationServiceImpl.selectForPage(index, limit, patientName, idCard, startTime, endTime);
    }


    /**
     * 根据病人id，科室名称新增挂号记录
     * 接诊状态设置为待诊 也就是 0
     * 挂号时间为当前系统时间
     * 流水号为时间戳毫秒数加上病人id(加法运算)
     *
     * @param patientId      病人id
     * @param departmentName 科室名称
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insertByPatientIdAndDepartmentName", method = RequestMethod.POST)
    @ApiOperation(value = "根据病人id，科室名称新增挂号记录", notes = "根据病人id，科室名称新增挂号记录", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "patientId", value = "病人id", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "departmentName", value = "科室名称", paramType = "query", dataType = "String", required = true)
    })
    public Map<String, Object> insertByPatientIdAndDepartmentName(@RequestParam(name = "patientId") Integer patientId, @RequestParam(name = "departmentName") String departmentName) {
        return registrationInformationServiceImpl.insertByPatientIdAndDepartmentName(patientId,departmentName);
    }

    /**
     * 根据挂号记录id修改接诊状态为已接诊 也就是 1
     *
     * @param registrationInformationId 挂号记录id
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/updateReceptionStateById", method = RequestMethod.POST)
    @ApiOperation(value = "根据挂号记录id修改接诊状态为已接诊", notes = "根据挂号记录id修改接诊状态为已接诊", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "registrationInformationId", value = "挂号记录id", paramType = "query", dataType = "int", required = true)
    })
    public Map<String, Object> updateReceptionStateById(@RequestParam(name = "registrationInformationId") Integer registrationInformationId) {
        return registrationInformationServiceImpl.updateReceptionStateById(registrationInformationId);
    }

}
